package edu.predatorwars.shared.models;

import java.awt.Point;
import java.io.Serializable;

import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;

@JsonIgnoreProperties(value={"width", "height"}, ignoreUnknown=true)
public class Board implements Serializable
{
	private final String name;
	private final Location[][] locations;
	private final int resourceCount;
	
	@JsonCreator
	public Board(@JsonProperty("name") String name, @JsonProperty("locations") Location[][] locations, 
			@JsonProperty("resourceCount") int resourceCount)
	{
		this.name = name;
		this.locations = locations;
		this.resourceCount = resourceCount;
	}
	
	/**
	 * Returns the name of this board, used to uniquely identify the board.
	 * @return
	 */
	public String getName()
	{
		return name;
	}
	
	/**
	 * Gets the board Location at the given x,y position.
	 * @param x
	 * @param y
	 * @return
	 */
	public Location getLocation(int x, int y)
	{
		if(locations.length>x && locations[x].length > y)
			return locations[x][y];
		return null;
	}
	
	/**
	 * Gets the board Location at the given point.
	 * @param point
	 * @return
	 */
	public Location getLocation(Point point)
	{
		if(locations.length>point.x && locations[0].length > point.y)
			return locations[point.x][point.y];
		return null;
	}
	
	public Location[][] getLocations() {
		return locations;
	}

	/**
	 * Gets how many Locations tall the board is.
	 * @return
	 */
	public int getHeight()
	{
		return locations[0].length;
	}
	
	/**
	 * Gets how many Locations wide the board is.
	 * @return
	 */
	public int getWidth()
	{
		return locations.length;
	}
	
	/**
	 * Returns the number of resources the board will start with.
	 */
	public int getResourceCount()
	{
		return resourceCount;
	}
}
